<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
  class MyPromise{
    constructor(cb){
      // 初始化参数
      this.initValue()
      // 执行对应方法
      cb(this.resolve.bind(this),this.reject)
    }

    // 初始化函数，初始状态与值
    // 使用箭头函数使this指向实例对象
    initValue = () =>{
      this.PromiseState = 'pending'
      this.PromiseResult = null
    }

    // resolve 方法
    resolve(value){
      this.PromiseState = 'fulfilled'
      this.PromiseResult = value
    }

    // reject 方法
    reject = (reason) =>{
      this.PromiseState = 'rejected'
      this.PromiseResult = reason
    }
  }

  //  测试代码
  let p1 = new MyPromise((resolve,reject)=>{
    resolve('成功')
  })
  console.log(p1);
</script>
</body>
</html>